﻿using System;

namespace Eneta.Portal.Common.Dto
{
    /// <summary>
    /// Class for IO classificator products. This class is marked as serializable to support 
    /// different caching mechanisms.
    /// </summary>
    [Serializable]
    public class IoProduct
    {
        /// <summary>
        /// Gets or sets the id of product.
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// Gets or sets the name of product.
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// Gets or sets the URL of product. This is URL to product home page.
        /// </summary>
        public string Url { get; set; }

        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        /// 	<c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">
        /// The <paramref name="obj"/> parameter is null.
        /// </exception>
        public override bool Equals(object obj)
        {
            var other = obj as IoProduct;
            if (other == null)
                return false;

            return (Id == other.Id);
        }

        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
        /// </returns>
        public override int GetHashCode()
        {
            var title = Title ?? string.Empty;
            return ("IoProduct:" + Id + ":" + title).GetHashCode();
        }
    }
}